﻿using System;
using System.Text.RegularExpressions;

namespace KingSite.Library.Tools
{

    /// <summary>
    /// 其他工具增强类
    /// </summary>
    /// Author:Jerry
    /// Date:2010-10-09
    public class Util
    {

        /// <summary>
        /// 将传入的对象转换为整数
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static int Convert2Int32(object o)
        {
            try { return Convert.ToInt32(o); }
            catch { return 0; }
        }

        /// <summary>
        /// 将传入的对象转换为时间
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static DateTime Convert2DateTime(object o)
        {
            try { return Convert.ToDateTime(o); }
            catch { return DateTime.MinValue; }
        }

        public static double Convert2Double(object o)
        {
            try { return Convert.ToDouble(o); }
            catch { return 0; }
        }

        /// <summary>
        /// 得到正则编译参数设置
        /// </summary>
        /// <returns>参数设置</returns>
        public static RegexOptions GetRegexCompiledOptions()
        {
            #if NET1
                return RegexOptions.Compiled;
            #else
            return RegexOptions.None;
            #endif
        }
    }
}
